package lab.dexter.bbsreader.managers;

import java.util.ArrayList;
import java.util.List;

import lab.dexter.bbsreader.ListManager;

import org.apache.http.HttpEntity;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import lab.dexter.bbsreader.R;

public class TestManager extends ListManager {
	public class TestItem {
		private String mTitle;
		
		public TestItem(String title) {
			mTitle = title;
		}

		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return mTitle;
		}
	}
	
	private List<TestItem> list;
	
	public TestManager(Context context) {
		super(context, null);
		list = new ArrayList<TestItem>();
	}

	@Override
	public int update() {
		int start = list.size();
		for(int i = 0; i < 10; i++) {
			list.add(new TestItem("title " + (i + start)));
		}
		list.add(new TestItem("test title"));
		Log.w("TAG", "size is " + list.size());
		return 0;
	}

	@Override
	public boolean onItemClick(int position) {
		Toast.makeText(mContext, "hello! " + position,
            Toast.LENGTH_SHORT).show();
		return false;
	}

	public void dataProcessor(HttpEntity entity) {
		// TODO Auto-generated method stub
		
	}

	public boolean areAllItemsEnabled() {
		// TODO Auto-generated method stub
		return true;
	}

	public boolean isEnabled(int position) {
		// TODO Auto-generated method stub
		return true;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	
	public int getItemViewType(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if(view == null) {
			LayoutInflater vi = (LayoutInflater)(mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
            view = vi.inflate(R.layout.test_item, parent);
		}
		TestItem it = list.get(position);
		if(it != null) {
			TextView tv = (TextView)view.findViewById(R.id.text);
			if(tv != null) {
				tv.setText(it.toString());
			}
		}
		return view;
	}

	public int getViewTypeCount() {
		return 1;
	}
}
